package sk.ygor.raynor.client.json.basetype;

import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONValue;
import sk.ygor.raynor.client.json.JSONSerializationException;

public class java_lang_Byte_JSONSerializer extends BaseTypeSerializer<Byte> {

    @Override
    protected Byte deserializeNonNullValue(JSONValue jsonValue) {
        JSONNumber number = jsonValue.isNumber();
        if (number != null) {
            return (byte) number.doubleValue();
        }
        throw new JSONSerializationException("Cannot create Byte from: " + jsonValue);
    }

    @Override
    protected JSONValue serializeNonNullValue(Byte javaValue) {
        return new JSONNumber(javaValue);
    }

}